package com.szqhyxj.youxiangju.biz.card.credit;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

import com.szqhyxj.youxiangju.BasePromptFragment;
import com.szqhyxj.youxiangju.R;
import com.szqhyxj.youxiangju.biz.card.CardModel;
import com.szqhyxj.youxiangju.biz.card.adapter.CardAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 信用卡
 * Created by xiaopanyu on 2018/8/23.
 */

public class CreditFragment extends BasePromptFragment implements CreditContarct.View{

    @BindView(R.id.creadits)
    ListView creadits;
    Unbinder unbinder;
    @BindView(R.id.no_prompt)
    LinearLayout noPrompt;
    private CreditPresenter creditPresenter;
    private CardAdapter adapter;
    private List<CardModel.Card> cards;
    public static CreditFragment newInstance(){
        Bundle args = new Bundle();
        CreditFragment fragment = new CreditFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState){
        super.onCreate(savedInstanceState);

    }


    @Override
    public void onResume(){
        super.onResume();
    }

    @Override
    protected int getLayoutId(){
        return R.layout.fragment_creadit;
    }

    @Override
    public void showCards(List<CardModel.Card> cards){
        noPrompt.setVisibility(View.GONE);
        creadits.setVisibility(View.VISIBLE);
        this.cards.clear();
        this.cards.addAll(cards);
        adapter.notifyDataSetChanged();
    }

    @Override
    public void showNoCard(){
        noPrompt.setVisibility(View.VISIBLE);
    }

    @Override
    public void navCardDetails(){
    }

    @Override
    public void showToast(String s){
        Toast.makeText(getActivity(), s, Toast.LENGTH_LONG).show();
    }

    @Override
    public void showRefresh(){
        creditPresenter.init();
    }

    @Override
    protected void start(){
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        creditPresenter = new CreditPresenter(this);
        cards = new ArrayList<>();
        adapter = new CardAdapter(getContext(), cards);
        creadits.setAdapter(adapter);
        return rootView;
    }

    @Override
    public void onDestroyView(){
        super.onDestroyView();
        unbinder.unbind();
    }
}
